import React, { useEffect, useState } from 'react'
import ProForm, { ProFormTextArea } from '@ant-design/pro-form';
import { Modal } from 'antd';
import { commentsReply } from '@/services/comments'
import { message } from 'antd';

export default function CreateOrEdit(props) {
  //表单数据
  const [initialValues, setInitialValues] = useState(undefined)
  //模态框是否显示
  //操作模态框显示隐藏的方法
  //父组件的传递过来的表格的引用，可以用来操作表格，比如刷新表格
  //要编辑的ID，添加的时候用undefined，只有编辑才有值
  const { isModalVisible, isShowModal, actionRef, editId } = props
  //提交表单，执行编辑或添加
  const handleSubmit = async values => {
    let res = {}
    if (editId) {
      res = await commentsReply(editId, values)
    }
    console.log(res);
    if (res.status === undefined) {
      message.success(`回复成功`)
      //刷新表格数据
      actionRef.current.reload()
      //关闭模态框
      isShowModal(false)
    }
  }
  return (
    <Modal title={`订单发货`} visible={isModalVisible}
      onCancel={() => isShowModal(false)} footer={null} destroyOnClose={true}>
      {
          <ProForm
            onFinish={values => handleSubmit(values)}
          >
            <ProFormTextArea
              name="reply"
              label="回复"
              placeholder="请输入回复内容"
              rules={[
                { required: true, message: '请输入回复内容！' },
              ]}
            />
          </ProForm>
      }

    </Modal>
  )
}
